package com.yuanfeng.action.admin.type.web;
import com.opensymphony.xwork2.ActionSupport;
import com.yuanfeng.pojo.Types;
import com.yuanfeng.action.admin.type.service.TypeService;
import com.yuanfeng.util.WebUtil;
import org.apache.struts2.ServletActionContext;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

public class TypeAction extends ActionSupport {

    /**
     * 业务逻辑模块依赖springIoc注入
     */
    private TypeService typeServiceImpl;

    public void setTypeServiceImpl(TypeService typeServiceImpl) {
        this.typeServiceImpl = typeServiceImpl;
    }
    /**
     * 查询所有分类
     * @return
     */
    public String queryTypes(){
        HttpServletRequest request = ServletActionContext.getRequest();
        // 查询出所有图书分类，然后放到request中去
        List<Types> types = typeServiceImpl.queryTypes();
        request.setAttribute("types", types);
        return "queryTypes";
    }

    /**
     * 保存
     * @return
     */
    public String save(){
        HttpServletRequest request = ServletActionContext.getRequest();
        Types types = WebUtil.copyRequestToBean(request, Types.class);
        types = typeServiceImpl.add(types);
        request.setAttribute("type", types);
        return "save";
    }
    /**
     * 删除分类
     * @return
     */
    public String  deleteTypes(){
        HttpServletRequest request = ServletActionContext.getRequest();
        Types types = WebUtil.copyRequestToBean(request, Types.class);
        typeServiceImpl.delete(types);
        return "deleteTypes";
    }

}
